﻿Imports DomusDotNet.Sbm.Services.Interfaces

Namespace Services.Implementations
    Public Class FakeAuthenticationService
        Inherits FakeServiceBase
        Implements IAuthenticationService

        Public Function ValidateSessionGuid(guid As String) As Boolean Implements Interfaces.IAuthenticationService.ValidateSessionGuid
            Dim retval = True
            If String.IsNullOrWhiteSpace(guid) Then
                retval = False
                Me._Errors.Add(New ServiceError() With {.Code = "ValidateSessionGuid",
                                                        .Message = "Guid non può essere vuoto."})
            Else
                Try
                    Dim objGuid = New Guid(guid)
                Catch ex As Exception
                    retval = False
                    Me._Errors.Add(New ServiceError() With {.Code = "ValidateSessionGuid",
                                                            .Message = "Guid non valido."})
                End Try
            End If
            Return retval
        End Function

        Public Function ValidateUser(username As String, password As String) As Boolean Implements Interfaces.IAuthenticationService.ValidateUser
            Dim retval = True
            If String.IsNullOrWhiteSpace(username) Then
                retval = False
                Me._Errors.Add(New ServiceError() With {.Code = "ValidateUser",
                                                        .Message = "Username non può essere vuoto."})
            ElseIf String.IsNullOrWhiteSpace(password) Then
                retval = False
                Me._Errors.Add(New ServiceError() With {.Code = "ValidateUser",
                                                        .Message = "Password non può essere vuota."})
            ElseIf username <> password Then
                retval = False
                Me._Errors.Add(New ServiceError() With {.Code = "ValidateUser",
                                                        .Message = "Utente sconosciuto."})
            End If
            Return retval
        End Function

        Protected _Errors As List(Of ServiceError) = New List(Of ServiceError)

        Public ReadOnly Property Errors As System.Collections.Generic.IEnumerable(Of ServiceError) Implements Interfaces.IServiceBase.Errors
            Get
                Return _Errors
            End Get
        End Property

#Region "IDisposable Support"
        Private disposedValue As Boolean ' To detect redundant calls

        ' IDisposable
        Protected Overridable Sub Dispose(disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
                    ' TODO: dispose managed state (managed objects).
                End If

                ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
                ' TODO: set large fields to null.
            End If
            Me.disposedValue = True
        End Sub

        ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
        'Protected Overrides Sub Finalize()
        '    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        '    Dispose(False)
        '    MyBase.Finalize()
        'End Sub

        ' This code added by Visual Basic to correctly implement the disposable pattern.
        Public Sub Dispose() Implements IDisposable.Dispose
            ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region

        
    End Class
End Namespace